const app = getApp();

// pages/order/order.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    hide: app.globalData.hide,
    active: 0,
    orderList: {
      tabs: ["全部", "待付款", "待发货", "待收货", "待评价", "售后"],
      goods: [
        {
          type: 0,
          status: 1,
          title: "待付款待付款待付款待付款待付款待付款待付款待付款",
          spec: "111",
          totalnum: 1,
          price: 99.99,
        },
        {
          type: 1,
          status: 2,
          title: "待发货待发货待发货待发货待发货待发货待发货待发货",
          spec: "111",
          totalnum: 2,
          price: 88.88,
        },
        {
          type: 2,
          status: 3,
          title: "待收货待收货待收货待收货待收货待收货待收货待收货",
          spec: "111",
          totalnum: 1,
          price: 128,
        },
        {
          type: 3,
          status: 4,
          title: "待评价待评价待评价待评价待评价待评价待评价待评价",
          spec: "111",
          totalnum: 3,
          price: 66.66,
        },
        {
          type: 4,
          status: 5,
          title: "售后售后售后售后售后售后售后售后售后售后售后售后",
          spec: "111",
          totalnum: 2,
          price: 188,
        },
      ],
    },
  },

  handle(e) {
    const { type } = e.currentTarget.dataset;
    switch (type) {
      case "cancel":
        wx.showModal({
          title: "操作提示",
          content: "确定要删除此订单吗？",
          confirmColor: "#1296db",
          success: (result) => {
            if (result.confirm) {
              wx.showToast({
                title: "取消成功",
                icon: "success",
              });
            }
          },
          fail: () => { },
          complete: () => { },
        });
        break;
      case "pay":
        wx.navigateTo({
          url: "/pages/order/pay/pay",
        });
        break;
      case "afterSale":
        wx.navigateTo({
          url: "/pages/order/afterSale/afterSale?pageType=1",
        });
        break;
      case "checkAfterSale":
        wx.navigateTo({
          url: "/pages/order/afterSale/afterSale?pageType=2",
        });
        break;
      case "cancelAfterSale":
        wx.showModal({
          title: "操作提示",
          content: "确定要取消该订单售后吗？",
          confirmColor: "#66a6ff ",
          success: (result) => {
            if (result.confirm) {
              wx.showToast({
                title: "取消成功",
                icon: "success",
              });
            }
          },
          fail: () => { },
          complete: () => { },
        });
        break;
      case "confirm":
        wx.showModal({
          title: "操作提示",
          content: "确定收到货物并确认无误吗？",
          confirmColor: "#1296db",
          success: (result) => {
            if (result.confirm) {
              wx.showToast({
                title: "收货成功",
                icon: "success",
              });
            }
          },
          fail: () => { },
          complete: () => { },
        });
        break;
      case "appraise":
        wx.navigateTo({
          url: "/pages/order/appraise/appraise?pageType=1",
        });
        break;
      case "pushAppraise":
        wx.navigateTo({
          url: "/pages/order/appraise/appraise?pageType=2",
        });
        break;
      case "logistics":
        wx.navigateTo({
          url: "/pages/order/logistics/logistics",
        });
        break;
      default:
        wx.showToast({
          title: "开发中：" + type,
          icon: "none",
        });
        break;
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // console.log(options);
    const active = +options.active;
    this.setData({
      active,
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() { },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() { },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() { },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() { },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() { },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() { },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() { },
});
